package cn.tedu.coolsharkmall.controller;

import cn.tedu.coolsharkmall.pojo.dto.AlbumUpdateDTO;
import cn.tedu.coolsharkmall.pojo.dto.AttributeTemplateAddNewDTO;
import cn.tedu.coolsharkmall.pojo.dto.AttributeTemplateUpdateDTO;
import cn.tedu.coolsharkmall.service.IAttributeTemplateService;
import cn.tedu.coolsharkmall.web.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Range;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/attribute-template/")
@Api(tags = "03. 属性模版管理模块")
@Slf4j
public class AttributeTemplateController {
    @Autowired
    IAttributeTemplateService service;

    @ApiOperation(" 添加属性模版")
    @PostMapping("add-new")
    public JsonResult addNew(@Validated AttributeTemplateAddNewDTO attributeTemplateAddNewDTO){
        log.debug("AttributeTemplateAddNewDTO = {}", attributeTemplateAddNewDTO);
        service.addNew(attributeTemplateAddNewDTO);
        return JsonResult.ok();
    }

    @ApiOperation("删除属性模版")
    @PostMapping("/{id:[0-9]+}/delete")
    @ApiImplicitParam(name = "id", value = "属性模版ID", dataType = "long", required = true, example = "1")
    public JsonResult delete(@PathVariable @Range(min = 1, message = " 请提交有效的id值!") Long id){
        service.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改相册")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "属性模版ID", dataType = "long", required = true, example = "1"),
    })
    public JsonResult updateInfoById(@PathVariable @Range(min = 1, message = " 请提交有效的id值!") Long id,
                                     @Validated AttributeTemplateUpdateDTO attributeTemplateUpdateDTO) {
        service.updateInfoById(id, attributeTemplateUpdateDTO);
        return JsonResult.ok();
    }



}
